//
//  MeDetailController.swift
//  BodyBuilding
//
//  Created by franze on 2017/10/8.
//  Copyright © 2017年 franze. All rights reserved.
//

import UIKit

class MeDetailController: UIViewController {
    var infoDict:NSDictionary!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        viewConfig()
    }
    
    func viewConfig(){
        view.backgroundColor = UIColor.gray
        
        let navBar = CustomNavBar(frame: CGRect(origin: .zero, size: CGSize(width: WIDTH, height: 64)))
        navBar.initialize(text: nil)
        view.addSubview(navBar)
        
        let scrollView = UIScrollView(frame: CGRect(x: 0, y: 64, width: WIDTH, height: HEIGHT-64))
        scrollView.contentInsetAdjustmentBehavior = .never
        scrollView.contentSize = CGSize(width: 0, height: 364+(HEIGHT-69)/3)
        scrollView.backgroundColor = view.backgroundColor
        scrollView.showsVerticalScrollIndicator = false
        view.addSubview(scrollView)
        
        let imageView = UIImageView()
        imageView.sd_setImage(with: URL(string: BB_IMAGEURLPRE+(infoDict.value(forKey: "thumb") as! String)), placeholderImage: UIImage(named:"placeholder"))
        imageView.frame = CGRect(x: 0, y: 0, width: WIDTH, height: (HEIGHT-69)/3)
        scrollView.addSubview(imageView)
        
        let label = UILabel(frame: CGRect(x: 15, y: imageView.bounds.height+10, width: WIDTH-30, height: 40))
        label.text = "简介"
        label.textAlignment = .center
        label.layer.cornerRadius = 5
        label.layer.borderColor = UIColor.lightGray.cgColor
        label.layer.borderWidth = 1
        scrollView.addSubview(label)
        
        let textView = UITextView(frame: CGRect(x: 15, y: label.frame.origin.y+50, width: WIDTH-30, height: 60))
        textView.text = infoDict.value(forKey: "introduction") as! String
        textView.isEditable = false
        textView.font = UIFont.systemFont(ofSize: 16)
        textView.layer.borderWidth = 1
        textView.layer.borderColor = UIColor.lightGray.cgColor
        scrollView.addSubview(textView)
        
        let timeLabel = UILabel(frame: CGRect(x: 15, y: textView.frame.origin.y+80, width: WIDTH-30, height: 20))
        timeLabel.text = "上课时间: pm 14:00~17:00"
        timeLabel.font = UIFont.systemFont(ofSize: 20)
        scrollView.addSubview(timeLabel)
        
        let addrLabel = UILabel(frame: CGRect(x: 15, y: timeLabel.frame.origin.y+35, width: WIDTH-30, height: 20))
        addrLabel.text = "授课地点: \(infoDict.value(forKey: "scene_name") as! String)"
        addrLabel.font = UIFont.systemFont(ofSize: 20)
        scrollView.addSubview(addrLabel)
        
        let priceLabel = UILabel(frame: CGRect(x: 15, y: addrLabel.frame.origin.y+35, width: WIDTH-30, height: 20))
        priceLabel.text = "课程价格: 每月400元"
        priceLabel.font = UIFont.systemFont(ofSize: 20)
        scrollView.addSubview(priceLabel)
        
        
        let joinBtn = UIButton(frame: CGRect(x: 0, y: addrLabel.frame.origin.y+140, width: 150, height: 44))
        joinBtn.backgroundColor = UIColor.blue
        joinBtn.center.x = WIDTH/2
        joinBtn.setTitle("立即报名", for: .normal)
        joinBtn.layer.cornerRadius = 6
        joinBtn.adjustsImageWhenDisabled = false
        scrollView.addSubview(joinBtn)
        
        joinBtn.addTarget(self, action: #selector(focus), for: .touchUpInside)
        navBar.backBtn.addTarget(self, action: #selector(back), for: .touchUpInside)
    }
    
    @objc func focus(sender:UIButton){

    }
    
    
    @objc func back(){
        _ = navigationController?.popViewController(animated: true)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
}
